package com.wanglibao.woodtrade.woodtrade.ui.activity.adapter;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.TextView;

import com.wanglibao.woodtrade.woodtrade.R;
import com.wanglibao.woodtrade.woodtrade.ui.activity.BuyActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

public class ItemLvSupplyAndDemendAdapter extends BaseAdapter implements View.OnClickListener {

    private List<String> mList = new ArrayList<>();

    private Context context;
    private LayoutInflater layoutInflater;
    boolean isok=false;

    public ItemLvSupplyAndDemendAdapter(Context context, List<String> objects) {
        this.context = context;
        this.mList=objects;
        this.layoutInflater = LayoutInflater.from(context);
        if(mList.size()!=10){
            isok=!isok;
        }
        notifyDataSetChanged();
    }

    public void setList(List<String> list) {
        mList = list;
        if(mList.size()!=10){
            isok=!isok;
        }
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public String getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = layoutInflater.inflate(R.layout.item_lv_trade_fragment, null);
            convertView.setTag(new ViewHolder(convertView));
        }
        initializeViews((String) getItem(position), (ViewHolder) convertView.getTag());
        return convertView;
    }

    private void initializeViews(String object, ViewHolder holder) {
        holder.btItemLvGonghuo.setText(object.toString());
        holder.btItemLvGonghuo.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        Intent intent=new Intent(context, BuyActivity.class);
        context.startActivity(intent);
    }

    static class ViewHolder {
        @Bind(R.id.tv_item_lv_qg_title) TextView tvItemLvQgTitle;
    @Bind(R.id.tv_item_lv_size) TextView tvItemLvSize;
    @Bind(R.id.tv_item_lv_qg_size) TextView tvItemLvQgSize;
    @Bind(R.id.tv_item_lv_danwei) TextView tvItemLvDanwei;
    @Bind(R.id.tv_item_lv_qg_danwei) TextView tvItemLvQgDanwei;
    @Bind(R.id.tv_item_lv_guige) TextView tvItemLvGuige;
    @Bind(R.id.tv_item_lv_qg_guige) TextView tvItemLvQgGuige;
    @Bind(R.id.bt_item_lv_gonghuo) Button btItemLvGonghuo;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
